package gui.feeds;

import gui.GUIUtils;

import java.util.List;

import javax.swing.JLabel;

import core.exceptions.DBAccessException;
import core.objects.Book;
import core.objects.NewsFeedItem;
import db.DBAccessEngine;
import db.threads.IDBAccessThread;

public class JFeedType2 extends JFeedComment {

	public JFeedType2(NewsFeedItem item) {
		super(item);
	}

	@Override
	protected IDBAccessThread getImageLoaderThread(final JLabel imageLabel) {
		return new IDBAccessThread() {
			
			@Override
			public Object onCreateQuery() throws DBAccessException {
				return DBAccessEngine.Book().select(item.getBookID());
			}
			
			@SuppressWarnings("unchecked")
			@Override
			public void onAccessFinished(Object response) {
				List<Book> books = (List<Book>)response;
				if (books.size() > 0 && books.get(0).getThumbnailURL() != null) {
		            GUIUtils.setImageAtSize(imageLabel, 60, 90, books.get(0).getThumbnailURL());
		        } else {
		            GUIUtils.setImageAtSize(imageLabel, 60, 90, "/resources/book.png");
		        }
			}
			
			@Override
			public void onAccessFailed(DBAccessException e) {
	            GUIUtils.setImageAtSize(imageLabel, 60, 90, "/resources/book.png");
			}
		};
	}

	@Override
	protected String getCommentedOn() {
		return "'" + item.getBookName() + "'";
	}

	@Override
	protected void loadPlaceHoldPicture(JLabel imageLabel) {
        GUIUtils.setImageAtSize(imageLabel, 60, 90, "/resources/book.png");		
	}

	@Override
	protected String getAction() {
		return "also ranked";
	}

}
